<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>盱眙供电局点位配置</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <link href="../../css/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" type="text/css">
    <script src="../../layui/layui.js"></script>
    <script src="../../js/jquery-1.8.3.js"></script>
    <script src="../../js/util.js"></script>
    <script src="../../js/jquery-ui-1.10.4.custom.min.js"></script>
    <link href="../../css/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" type="text/css">
    <style type="text/css">
        .ui-autocomplete {
            max-width:155px;
            max-height: 300px;
            overflow-x: auto;
            overflow-y: auto;
        }
    </style>
    <script>
        layui.use(['table', 'form', 'jquery', 'element','layer'], function () {
            var table = layui.table;
            var form = layui.form;
            var $ = layui.$;
            var layer=layui.layer;
            var user;
            var options = {
                elem: "#table",
                id: "modelReload",
                url: '/xuYiPoint/findPointInfoList',
                method: 'post',
                request: {
                    pageName: 'page',
                    limitName: 'limit'
                },
                response: {
                    statusName: 'code',
                    statusCode: 0,
                    msgName: 'msg',
                    countName: 'count',
                    dataName: 'data'
                },
                loading: true,
                page: {
                    count: "count",
                    limit: 10,
                    limits: [10, 20,30,40,50],
                    layout: ['prev', 'page', 'next', 'skip', 'limit', 'count'],
                    prev: "上一页",
                    next: "下一页",
                    groups: 5
                },
                cols: [[ //表头
                    {field: 'name', title: '点位名称',align:'center',width: '50%'},
                    {field: 'operation', title: '操作',align:'center', toolbar: '#barDemo'}
                ]],
                done: function (res) {
                    // console.log(JSON.stringify(res));
                }
            };

    		table.render(options);
    		table.on('tool(tableElement)', function (obj) {
                 var data = obj.data;
					 if (obj.event == 'relateStation') {
					 console.info(data.name);
                    window.location.href = encodeURI('xuYiRegionRelateCommit.html?regionName=' + encodeURIComponent(data.name));
                } 
            });
            //更新数据表
            $('#query').on('click', function () {
  	       		
  	       			var regionName=$("#subStationName").val();
  	       			var regionNameText = $("#regionName").val();
  	       			console.info("----"+regionName);
  	       			
  	       			if(isNull(regionNameText)){
  	       				console.info("xuanze");
  	       			}else{
  	       				console.info("tainxie");
  	       				regionName = regionNameText;
  	       			}
  	       			
  	       			/*if (regionName == null || regionName== "") {
                            layer.msg("点位信息不能为空");
                            return false;
                    }  */
                    
                    if("all"==regionName)   {
                    	regionName = "";
                    }
                    var index = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    
                    console.info(regionName);
                    //table.render(options);
                    table.reload('modelReload', {
                    method: 'post',
                    page: {
                        curr: 1
                    },
                    where: {
                        pointNameText: regionName
                    }
                });
                layer.close(index);
                
            });
            
            $('#insert').on('click', function () {
                window.location.href = 'xuYiSubStationAdd.html';
            });

            
            
            $('#relate').on('click', function () {
                window.location.href = 'xuYiRegionManage.html';
            });
            
            
            //身份识别
            $(document).ready(function () {
                qryPointNameList('');
            });


            function qryPointNameList(pointNameText) {
                var data;
                var url = '/xuYiPoint/findPointNameList2';
                var param = {
                    pointNameText : pointNameText,
                };
                $.ajax({
                        type: 'post',
                        async: false,
                        url: url,
                        data : param,
                        success: function (json) {
                            data = json.data;
                            if (data.length != null) {
                                var options = '<option value="">请选择点位</option>';
                                for (var i = 0; i < data.length; i++) {
                                    //console.info(data[i]);
                                    options += '<option value="' + data[i].name + '">' + data[i].name + '</option>';
                                }
                                $('#subStationName').html(options);
                            } else {
                                $('#subStationName').html('暂无点位信息');
                            }
                            form.render();

                        }, error: function () {
                            layer.msg('系统异常，请联系管理员处理!');
                        }
                    }
                );
                return data;
            }

            $("#regionName").autocomplete({
                source : function(request, response) {
                    var pointNameText = $("#regionName").val();
                    console.info(pointNameText);
                    var url = '/xuYiPoint/findPointNameList2';
                    var param = {
                        pointNameText : pointNameText
                    };
                    $.ajax({
                            type : 'post',
                            async : false,
                            url : url,
                            data : param,
                            success : function(json) {
                                var data = json.data;
                                source = [];
                                for (var i = 0; i < data.length; i++) {
                                    source[i] = data[i].name;
                                }
                                console.log(source);
                                response(source);
                            },
                            error : function() {
                                layer.msg('系统异常，请联系管理员处理!');
                            }
                        }
                    );
                },
                messages : { //message设置不出现匹配关键字的结果
                    noResults : '',
                    results : function() {}
                }
            });
        });

    </script>
    <script type="text/html" id="barDemo">
        <a href="javascript:void(0)" lay-event="relateStation" id="relateStation">关联基站</a>
    </script>
</head>
<body>
<div class="layui-content-body">
    <div class="scroll-box">
        <div class="breadcrumb-box">
            <span class="layui-breadcrumb" lay-separator="|">
                     <a href="javascript:returnIndex2()">首页&nbsp;</a>
                  <a href="#">点位基站配置</a>
            </span>
        </div>
        <div class="content-box">
            <div class="form-select-box">
                <div class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width:120px;">点位:</label>
                            <div class="layui-input-block" style="width:150px;margin-left:120px;">
                                <select name="subStationName" lay-filter="subStationName" id="subStationName">
                                   <option value="">请先选择路线</option>
                                </select>
                            </div>
                        </div>
                     <div class="layui-inline" >
                        <div class="layui-block" pane="">
                            <label class="layui-form-label" style="width:120px">点位名称:</label>
                            <div class="layui-input-block" style="width:160px;margin-left:120px;">
			                    <input type="text" name="regionName" id="regionName" required lay-verify="required"
			                           placeholder="请输入点位名称"
			                           autocomplete="off" class="layui-input">
			                </div>
                        </div>
                    </div>
                        <div class="layui-inline" pane="">
                            <button class="layui-btn layui-btn-normal" id="query">查&nbsp;询</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-table">
                <table id="table" lay-filter="tableElement"></table>
            </div>
        </div>
    </div>
</div>
</body>
</html>